﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Directory.Web
{
    public partial class Admin_SiteSettings : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
			if (!IsPostBack)
			{
				BindUI();
			}
        }
		// 保存设置
		protected void btnSave_Click(object sender, EventArgs e)
		{
			WebSettings.GetInstance().SiteName = tbSiteName.Text.Trim();
			WebSettings.GetInstance().HostName = tbHostName.Text.Trim();
			try
			{
				WebSettings.SaveSettings();
				ClientScript.RegisterClientScriptBlock(this.GetType(), null, "<script>alert('保存成功。');</script>");
			}
			catch
			{
				ClientScript.RegisterClientScriptBlock(this.GetType(), null, "<script>alert('服务器错误：未知错误。');</script>");
			}
		}
		// 重新加载设置
		protected void btnResetSettings_Click(object sender, EventArgs e)
		{
			try
			{
				WebUtil.ResetSettings();
				BindUI();
			}
			catch
			{
				ClientScript.RegisterClientScriptBlock(this.GetType(), null, "<script>alert('服务器错误：未知错误。');</script>");
			}
		}

		private void BindUI()
		{
			tbSiteName.Text = WebSettings.GetInstance().SiteName;
			tbHostName.Text = WebSettings.GetInstance().HostName;
		}
}
}
